In [1]:
import numpy as np
import pandas as pd
import os,sys
from pathlib import Path
import matplotlib.pyplot as plt

cwd = os.getcwd() #grabs current working directory

testfolder = str(Path().resolve().parent.parent / 'PV_ICE' / 'TEMP' / 'EnergyAnalysis'/'Sensitivity')
inputfolder = str(Path().resolve().parent.parent / 'PV_ICE' / 'TEMP')
baselinesfolder = str(Path().resolve().parent.parent /'PV_ICE' / 'baselines')
supportMatfolder = str(Path().resolve().parent.parent / 'PV_ICE' / 'baselines' / 'SupportingMaterial')
altBaselinesfolder = str(Path().resolve().parent.parent / 'PV_ICE' / 'baselines' / 'Energy_CellModuleTechCompare')

if not os.path.exists(testfolder):
    os.makedirs(testfolder)
In [2]:
from platform import python_version 
print(python_version())
3.8.8
In [3]:
import PV_ICE
PV_ICE.__version__
Out[3]:
'v0.2.0+487.g11edddb.dirty'
In [4]:
MATERIAL = ['glass']#
moduleFile_m = os.path.join(baselinesfolder, 'TEST_baseline_modules_mass_US.csv')
moduleFile_e = os.path.join(baselinesfolder, 'TEST_baseline_modules_energy.csv')
In [5]:
#load in a baseline and materials for modification
sim1 = PV_ICE.Simulation(name='sim1', path=testfolder)

sim1.createScenario(name='No_circ', massmodulefile=moduleFile_m, energymodulefile=moduleFile_e)
for mat in range (0, len(MATERIAL)):
    matbaseline_m = os.path.join(baselinesfolder,'TEST_baseline_material_mass_'+MATERIAL[mat]+'.csv')
    matbaseline_e = os.path.join(baselinesfolder,'TEST_baseline_material_energy_'+MATERIAL[mat]+'.csv')
    sim1.scenario['No_circ'].addMaterial(MATERIAL[mat], massmatfile=matbaseline_m, energymatfile=matbaseline_e)
path = C:\Users\hmirletz\Documents\GitHub\PV_ICE\PV_ICE\TEMP\EnergyAnalysis\Sensitivity
Baseline folder directed to default:  C:\Users\hmirletz\Documents\GitHub\PV_ICE\PV_ICE\baselines
In [6]:
sim1.createScenario(name='circ_mfg_LQ', massmodulefile=moduleFile_m, energymodulefile=moduleFile_e)
for mat in range (0, len(MATERIAL)):
    matbaseline_m = os.path.join(baselinesfolder,'TEST_baseline_material_mass_'+MATERIAL[mat]+'.csv')
    matbaseline_e = os.path.join(baselinesfolder,'TEST_baseline_material_energy_'+MATERIAL[mat]+'.csv')
    sim1.scenario['circ_mfg_LQ'].addMaterial(MATERIAL[mat], massmatfile=matbaseline_m, energymatfile=matbaseline_e)
    
#mod mod
#sim1.modifyScenario('MFGScrap_LQ', '',100.0, start_year=1995) #collect everything

#mat mod
sim1.scenario['circ_mfg_LQ'].modifyMaterials('glass', 'mat_MFG_scrap_Recycled',100.0, start_year=1995) #
In [7]:
sim1.createScenario(name='circ_mfg_HQOL', massmodulefile=moduleFile_m, energymodulefile=moduleFile_e)
for mat in range (0, len(MATERIAL)):
    matbaseline_m = os.path.join(baselinesfolder,'TEST_baseline_material_mass_'+MATERIAL[mat]+'.csv')
    matbaseline_e = os.path.join(baselinesfolder,'TEST_baseline_material_energy_'+MATERIAL[mat]+'.csv')
    sim1.scenario['circ_mfg_HQOL'].addMaterial(MATERIAL[mat], massmatfile=matbaseline_m, energymatfile=matbaseline_e)
    
#mod mod
#sim1.modifyScenario('MFGScrap_LQ', '',100.0, start_year=1995) #collect everything

#mat mod
sim1.scenario['circ_mfg_HQOL'].modifyMaterials('glass', 'mat_MFG_scrap_Recycled',100.0, start_year=1995) #
sim1.scenario['circ_mfg_HQOL'].modifyMaterials('glass', 'mat_MFG_scrap_Recycled_into_HQ',100.0, start_year=1995) #
In [8]:
sim1.createScenario(name='circ_mfg_HQCL', massmodulefile=moduleFile_m, energymodulefile=moduleFile_e)
for mat in range (0, len(MATERIAL)):
    matbaseline_m = os.path.join(baselinesfolder,'TEST_baseline_material_mass_'+MATERIAL[mat]+'.csv')
    matbaseline_e = os.path.join(baselinesfolder,'TEST_baseline_material_energy_'+MATERIAL[mat]+'.csv')
    sim1.scenario['circ_mfg_HQCL'].addMaterial(MATERIAL[mat], massmatfile=matbaseline_m, energymatfile=matbaseline_e)
    
#mod mod
#sim1.modifyScenario('MFGScrap_LQ', '',100.0, start_year=1995) #collect everything

#mat mod
sim1.scenario['circ_mfg_HQCL'].modifyMaterials('glass', 'mat_MFG_scrap_Recycled',100.0, start_year=1995) #
sim1.scenario['circ_mfg_HQCL'].modifyMaterials('glass', 'mat_MFG_scrap_Recycled_into_HQ',100.0, start_year=1995) #
sim1.scenario['circ_mfg_HQCL'].modifyMaterials('glass', 'mat_MFG_scrap_Recycled_into_HQ_Reused4MFG',100.0, start_year=1995) #
In [9]:
sim1.calculateFlows()
>>>> Calculating Material Flows <<<<

Working on Scenario:  No_circ
********************
Finished Area+Power Generation Calculations
==> Working on Material :  glass
Working on Scenario:  circ_mfg_LQ
********************
Finished Area+Power Generation Calculations
==> Working on Material :  glass
Working on Scenario:  circ_mfg_HQOL
********************
Finished Area+Power Generation Calculations
==> Working on Material :  glass
Working on Scenario:  circ_mfg_HQCL
********************
Finished Area+Power Generation Calculations
==> Working on Material :  glass


>>>> Calculating Energy Flows <<<<

Working on Scenario:  No_circ
********************
==> Working on Energy for Material :  glass
Working on Scenario:  circ_mfg_LQ
********************
==> Working on Energy for Material :  glass
Working on Scenario:  circ_mfg_HQOL
********************
==> Working on Energy for Material :  glass
Working on Scenario:  circ_mfg_HQCL
********************
==> Working on Energy for Material :  glass
In [10]:
cc_yearly, cc_cumu = sim1.aggregateResults()
allenergy, energyGen, energy_demands = sim1.aggregateEnergyResults()
C:\Users\hmirletz\Documents\GitHub\PV_ICE\PV_ICE\main.py:2236: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  scende_demands.loc[:,colname] = scende_demands.sum(axis=1) #sums module and material energy demands
C:\Users\hmirletz\Documents\GitHub\PV_ICE\PV_ICE\main.py:2236: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  scende_demands.loc[:,colname] = scende_demands.sum(axis=1) #sums module and material energy demands
C:\Users\hmirletz\Documents\GitHub\PV_ICE\PV_ICE\main.py:2236: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  scende_demands.loc[:,colname] = scende_demands.sum(axis=1) #sums module and material energy demands
C:\Users\hmirletz\Documents\GitHub\PV_ICE\PV_ICE\main.py:2236: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  scende_demands.loc[:,colname] = scende_demands.sum(axis=1) #sums module and material energy demands
In [11]:
sim1.plotMetricResults()
[]
In [12]:
plt.plot(cc_yearly.filter(like='VirginStock_glass'))
plt.legend(cc_yearly.filter(like='VirginStock_glass').columns)
Out[12]:
<matplotlib.legend.Legend at 0x1b7d4f56be0>
In [13]:
allenergy.filter(like='MFGScrap_LQ').tail(10)
Out[13]:
No_circ_glass_mat_MFGScrap_LQ circ_mfg_LQ_glass_mat_MFGScrap_LQ circ_mfg_HQOL_glass_mat_MFGScrap_LQ circ_mfg_HQCL_glass_mat_MFGScrap_LQ
year
2041 0.0 1.460678e+07 1.460678e+07 1.460678e+07
2042 0.0 1.456464e+07 1.456464e+07 1.456464e+07
2043 0.0 1.452440e+07 1.452440e+07 1.452440e+07
2044 0.0 1.448591e+07 1.448591e+07 1.448591e+07
2045 0.0 1.444903e+07 1.444903e+07 1.444903e+07
2046 0.0 1.441363e+07 1.441363e+07 1.441363e+07
2047 0.0 1.437960e+07 1.437960e+07 1.437960e+07
2048 0.0 1.434683e+07 1.434683e+07 1.434683e+07
2049 0.0 1.431526e+07 1.431526e+07 1.431526e+07
2050 0.0 1.428478e+07 1.428478e+07 1.428478e+07
In [14]:
plt.plot(allenergy.filter(like='MFGScrap_LQ'))
plt.legend(allenergy.filter(like='MFGScrap_LQ').columns)
Out[14]:
<matplotlib.legend.Legend at 0x1b7d4fc88b0>
In [15]:
allenergy.filter(regex='MFGScrap_HQ$').tail(10)
Out[15]:
No_circ_glass_mat_MFGScrap_HQ circ_mfg_LQ_glass_mat_MFGScrap_HQ circ_mfg_HQOL_glass_mat_MFGScrap_HQ circ_mfg_HQCL_glass_mat_MFGScrap_HQ
year
2041 0.0 0.0 1.460678e+07 1.460678e+07
2042 0.0 0.0 1.456464e+07 1.456464e+07
2043 0.0 0.0 1.452440e+07 1.452440e+07
2044 0.0 0.0 1.448591e+07 1.448591e+07
2045 0.0 0.0 1.444903e+07 1.444903e+07
2046 0.0 0.0 1.441363e+07 1.441363e+07
2047 0.0 0.0 1.437960e+07 1.437960e+07
2048 0.0 0.0 1.434683e+07 1.434683e+07
2049 0.0 0.0 1.431526e+07 1.431526e+07
2050 0.0 0.0 1.428478e+07 1.428478e+07
In [16]:
plt.plot(allenergy.filter(regex='MFGScrap_HQ$'))
plt.legend(allenergy.filter(regex='MFGScrap_HQ$').columns)
Out[16]:
<matplotlib.legend.Legend at 0x1b7d5984a90>
In [17]:
allenergy['circ_mfg_HQOL_glass_mat_MFGScrap_HQ']#-allenergy['circ_mfg_HQOL_glass_mat_MFGScrap_LQ']
#-allenergy['circ_mfg_LQ_glass_mat_MFGScrap_LQ']
Out[17]:
year
1995    2.857143e+07
1996    2.812148e+07
1997    2.772848e+07
1998    2.734631e+07
1999    2.697454e+07
2000    2.661273e+07
2001    2.626050e+07
2002    2.602660e+07
2003    2.579684e+07
2004    2.557109e+07
2005    2.534926e+07
2006    2.513124e+07
2007    2.491694e+07
2008    2.470627e+07
2009    2.449913e+07
2010    2.429543e+07
2011    2.365184e+07
2012    2.319109e+07
2013    2.232143e+07
2014    2.191060e+07
2015    2.100840e+07
2016    2.040816e+07
2017    2.017756e+07
2018    1.940994e+07
2019    1.860119e+07
2020    1.785714e+07
2021    1.708817e+07
2022    1.692620e+07
2023    1.631842e+07
2024    1.608344e+07
2025    1.589396e+07
2026    1.573550e+07
2027    1.559952e+07
2028    1.548054e+07
2029    1.537489e+07
2030    1.527993e+07
2031    1.519376e+07
2032    1.511491e+07
2033    1.504228e+07
2034    1.497497e+07
2035    1.491228e+07
2036    1.485364e+07
2037    1.479855e+07
2038    1.474664e+07
2039    1.469755e+07
2040    1.465102e+07
2041    1.460678e+07
2042    1.456464e+07
2043    1.452440e+07
2044    1.448591e+07
2045    1.444903e+07
2046    1.441363e+07
2047    1.437960e+07
2048    1.434683e+07
2049    1.431526e+07
2050    1.428478e+07
Name: circ_mfg_HQOL_glass_mat_MFGScrap_HQ, dtype: float64
In [18]:
allenergy['circ_mfg_LQ_glass_mat_MFGScrap_LQ']
Out[18]:
year
1995    2.857143e+07
1996    2.812148e+07
1997    2.772848e+07
1998    2.734631e+07
1999    2.697454e+07
2000    2.661273e+07
2001    2.626050e+07
2002    2.602660e+07
2003    2.579684e+07
2004    2.557109e+07
2005    2.534926e+07
2006    2.513124e+07
2007    2.491694e+07
2008    2.470627e+07
2009    2.449913e+07
2010    2.429543e+07
2011    2.365184e+07
2012    2.319109e+07
2013    2.232143e+07
2014    2.191060e+07
2015    2.100840e+07
2016    2.040816e+07
2017    2.017756e+07
2018    1.940994e+07
2019    1.860119e+07
2020    1.785714e+07
2021    1.708817e+07
2022    1.692620e+07
2023    1.631842e+07
2024    1.608344e+07
2025    1.589396e+07
2026    1.573550e+07
2027    1.559952e+07
2028    1.548054e+07
2029    1.537489e+07
2030    1.527993e+07
2031    1.519376e+07
2032    1.511491e+07
2033    1.504228e+07
2034    1.497497e+07
2035    1.491228e+07
2036    1.485364e+07
2037    1.479855e+07
2038    1.474664e+07
2039    1.469755e+07
2040    1.465102e+07
2041    1.460678e+07
2042    1.456464e+07
2043    1.452440e+07
2044    1.448591e+07
2045    1.444903e+07
2046    1.441363e+07
2047    1.437960e+07
2048    1.434683e+07
2049    1.431526e+07
2050    1.428478e+07
Name: circ_mfg_LQ_glass_mat_MFGScrap_LQ, dtype: float64
In [19]:
allenergy['circ_mfg_HQOL_glass_mat_MFGScrap_LQ']
Out[19]:
year
1995    2.857143e+07
1996    2.812148e+07
1997    2.772848e+07
1998    2.734631e+07
1999    2.697454e+07
2000    2.661273e+07
2001    2.626050e+07
2002    2.602660e+07
2003    2.579684e+07
2004    2.557109e+07
2005    2.534926e+07
2006    2.513124e+07
2007    2.491694e+07
2008    2.470627e+07
2009    2.449913e+07
2010    2.429543e+07
2011    2.365184e+07
2012    2.319109e+07
2013    2.232143e+07
2014    2.191060e+07
2015    2.100840e+07
2016    2.040816e+07
2017    2.017756e+07
2018    1.940994e+07
2019    1.860119e+07
2020    1.785714e+07
2021    1.708817e+07
2022    1.692620e+07
2023    1.631842e+07
2024    1.608344e+07
2025    1.589396e+07
2026    1.573550e+07
2027    1.559952e+07
2028    1.548054e+07
2029    1.537489e+07
2030    1.527993e+07
2031    1.519376e+07
2032    1.511491e+07
2033    1.504228e+07
2034    1.497497e+07
2035    1.491228e+07
2036    1.485364e+07
2037    1.479855e+07
2038    1.474664e+07
2039    1.469755e+07
2040    1.465102e+07
2041    1.460678e+07
2042    1.456464e+07
2043    1.452440e+07
2044    1.448591e+07
2045    1.444903e+07
2046    1.441363e+07
2047    1.437960e+07
2048    1.434683e+07
2049    1.431526e+07
2050    1.428478e+07
Name: circ_mfg_HQOL_glass_mat_MFGScrap_LQ, dtype: float64
In [20]:
e_annual_sumDemands = energy_demands.filter(like='demand_total')
e_annual_sumDemands_cumu = e_annual_sumDemands.cumsum()
cumu_e_demands = e_annual_sumDemands_cumu.iloc[-1]
cumu_e_demands.index= sim1.scenario.keys()

plt.bar(sim1.scenario.keys(), cumu_e_demands/cumu_e_demands['No_circ']-1)
plt.title('Cumulative Lifecycle Energy Demands')
plt.ylabel('Cumulative Energy Demands\n[TWh]')
Out[20]:
Text(0, 0.5, 'Cumulative Energy Demands\n[TWh]')
In [21]:
cumu_e_demands
Out[21]:
No_circ          1.487592e+11
circ_mfg_LQ      1.497693e+11
circ_mfg_HQOL    1.508489e+11
circ_mfg_HQCL    1.481320e+11
Name: 2050, dtype: float64